﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;
using l1cs.server.serverpackets;
using l1cs.server.model;

namespace l1cs.server.clientpackets
{
    public class C_Exclude : ClientBasePacket
    {
        private const String _C_EXCLUDE = "[C] C_Exclude";
        private static Logger _log = Logger.getLogger( typeof( C_Exclude ).FullName );

        /**
         * C_1 /exclude コマンドを打った時に送られる
         */
        public C_Exclude( byte[] decrypt, ClientThread client )
            : base( decrypt )
        {
            String name = readS();
            if ( name.Length == 0 )
            {
                return;
            }
            L1PcInstance pc = client.getActiveChar();
            L1ExcludingList exList = pc.getExcludingList();
            if ( exList.isFull() )
            {
                pc.sendPackets( new S_ServerMessage( 472 ) ); // \f1遮断されたユーザーが多すぎます。
                return;
            }
            if ( exList.contains( name ) )
            {
                String temp = exList.remove( name );
                pc.sendPackets( new S_PacketBox( S_PacketBox.REM_EXCLUDE, temp ) );
            }
            else
            {
                exList.add( name );
                pc.sendPackets( new S_PacketBox( S_PacketBox.ADD_EXCLUDE, name ) );
            }
        }

        override
        public String getType()
        {
            return _C_EXCLUDE;
        }
    }
}